﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FTP_progress
{
    public partial class Setting : Form
    {
        private dataGridView _dbHelper;
        public event Action DataUpdated;
        public Setting()
        {
            InitializeComponent();
            this.Text = "设置窗口";
            this.Size = new Size(1030, 650);

            // 创建DataGridView
            var dataGridView1 = new DataGridView
            {
                Dock = DockStyle.Fill,
                Name = "dataGridView1",
                
            };
           

            // 创建控制面板
            var controlPanel = new Panel
            {
                Dock = DockStyle.Top,
                Height = 40,
                BackColor = SystemColors.Control
            };

            // 加载按钮
            var loadBtn = new Button
            {
                Text = "加载数据",
                Size = new Size(80, 30),
                Location = new Point(10, 5)
            };

            // 保存按钮
            var saveBtn = new Button
            {
                Text = "保存更改",
                Size = new Size(80, 30),
                Location = new Point(100, 5)
            };

            // 添加到控制面板
            controlPanel.Controls.Add(loadBtn);
            controlPanel.Controls.Add(saveBtn);

            // 添加到窗体
            this.Controls.Add(dataGridView1);
            this.Controls.Add(controlPanel);

            // 创建数据库帮助类实例
            _dbHelper = new dataGridView(@"RobotConfigureDB", dataGridView1, "tab", "ID");

            // 绑定按钮事件
            loadBtn.Click += (s, e) => _dbHelper.LoadData();
            saveBtn.Click += (s, e) => _dbHelper.SaveChanges();

            _dbHelper.SetColumnWidth("id", 50);     
            _dbHelper.SetColumnWidth("Robot", 100);  
            _dbHelper.SetColumnWidth("FileType", 100);
            _dbHelper.SetColumnWidth("Server", 120);     
            _dbHelper.SetColumnWidth("RemoteFilePath", 100);  
            _dbHelper.SetColumnWidth("LocalFilePath", 150);
            _dbHelper.SetColumnWidth("GitlabURL", 350);     
          

            // 初始加载数据
            _dbHelper.LoadData();

         

        }


        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            _dbHelper.Dispose();
        }

     

     


        private void Setting_FormClosing(object sender, FormClosingEventArgs e)
        {

            DataUpdated?.Invoke();
        }

        private void Setting_Load(object sender, EventArgs e)
        {

        }
    }
}



